import traceback

from fastapi.responses import HTMLResponse
from fastapi import APIRouter, HTTPException, Query

from tasks.utils import get_html_by_selenium

router = APIRouter(tags=['Crawling'], prefix='/crawling')


@router.get("", summary="爬取一个链接获取 page source ", response_model=str)
def m3u8(
        url: str = Query(..., description="url")
):
    try:
        return HTMLResponse(get_html_by_selenium(url=url))
    except Exception as e:
        traceback.print_exc()
        raise HTTPException(status_code=500, detail=str(e))
